﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Contacts : System.Web.UI.Page
{
    LocalFunctions FUNC;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        FUNC = ((Admin)this.Master).FUNC;

        lblPageName.Text = FUNC.GetPhrase(6);
        lblKeywords.Text = FUNC.GetPhrase(7);
        lblDescription.Text = FUNC.GetPhrase(8);

        btnArticleSave.Text = FUNC.GetPhrase(9);

        lblTextTitle.Text = FUNC.GetPhrase(10);
        lblTextContent.Text = FUNC.GetPhrase(11);
        lblEmail.Text=FUNC.GetPhrase(18);
        // Get data from DB about page
        if (!IsPostBack)
        {
            GetParameters();
            GetPageData();
        }

        
    }

    private void GetParameters()
    {
        //hfID.Value = Request.QueryString["ID"];
        
        //Int32.TryParse(hfID.Value, out iPageID);
    }

    private void GetPageData()
    {
        
            Dal.arParams.Clear();
            Dal.arParams.Add(4); // typeID - 4 - Contacts
            DataTable DT = Dal.ExecuteDBsp("Admin_GetPageByID", Dal.arParams);

            // If not null - fill fields
            if (DT != null)
                if (DT.Rows.Count > 0)
                {
                    DataRow Row = DT.Rows[0];

                    hfID.Value = Row["ID"].ToString();
                    
                    txtPageTitle.Text = Row["PageTitle"].ToString();
                    txtKeywords.Text = Row["Keywords"].ToString();
                    txtDescription.Text = Row["Description"].ToString();

                    txtMainBlockTitle.Text = Row["Title"].ToString();
                    txtContent.Text = Helper.ConvertStringFromSql(Row["Content"].ToString());
                }

        txtEmail.Text=Dal.ExecuteDBspOneValue("Admin_GetEMail",null).ToString();
    }

    protected void btnArticleSave_Click(object sender, EventArgs e)
    {
        Dal.arParams.Clear();
        Dal.arParams.Add(Convert.ToInt32(hfID.Value)); //Page ID
        Dal.arParams.Add(txtPageTitle.Text);
        Dal.arParams.Add(txtKeywords.Text);
        Dal.arParams.Add(txtDescription.Text);
        Dal.arParams.Add(txtMainBlockTitle.Text); //Title
        Dal.arParams.Add(Helper.ConvertStringToSql(txtContent.Text)); //Content
        Dal.ExecuteDBsp("Admin_UpdatePageByID", Dal.arParams,true);

        Dal.arParams.Clear();
        Dal.arParams.Add(txtEmail.Text); //Page ID
        Dal.ExecuteDBsp("Admin_SetEmail", Dal.arParams, true);

    }
}